<?php

namespace app\api\controller\plus\invitationgift;


use app\api\controller\Controller;
use app\api\model\plus\invitationgift\InvitationGift as InvitationGiftModel;

/**
 * 邀请有礼控制器
 */
class Invitation extends Controller
{
    /**
     * 获取数据
     */
    public function getDatas($invitation_gift_id, $url = '')
    {
        $user = $this->getUser();
        $model = new InvitationGiftModel();
        $data = $model->getDatas($invitation_gift_id, $user['user_id']);
        if ($data) {
            // 微信公众号分享参数
            $share = $this->getShareParams($url, $data['share_title'], $data['share_desc'], '/pages/share/share', $data['share']['file_path']);
            return $this->renderSuccess('', compact('data', 'share'));
        }
        return $this->renderError($model->getError() ?: '活动不存在');
    }

    /**
     * 获取被邀请人数据
     */
    public function inviteInfo($invitation_gift_id)
    {
        $model = new InvitationGiftModel();
        $data = $model->inviteInfo($invitation_gift_id);
        if ($data) {
            $image = $data['invImage'] ? $data['invImage']['file_path'] : '';
            return $this->renderSuccess('', compact('image'));
        }
        return $this->renderError($model->getError() ?: '活动不存在');
    }
}